package com.sdkj.dspservice.modules.doc.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.sdkj.dspservice.common.base.service.impl.CrudServiceImpl;
import com.sdkj.dspservice.common.config.Global;
import com.sdkj.dspservice.common.utils.StringUtils;
import com.sdkj.dspservice.modules.doc.dao.DocDao;
import com.sdkj.dspservice.modules.doc.entity.Doc;
import com.sdkj.dspservice.modules.doc.service.DocService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author tm
 */
@Service
@Transactional(readOnly = true)
public class DocServiceImpl extends CrudServiceImpl<DocDao, Doc> implements DocService {

    @Override
    @Transactional(readOnly = false)
    public boolean saveOrUpdate(Doc doc) {
        if(StringUtils.isBlank(doc.getIsTop())){
            doc.setIsTop(Global.NO);
        }
        if(doc.getBrowseNumber() == null){
            doc.setBrowseNumber(0);
        }
        if(doc.getDownloadNumber() == null){
            doc.setDownloadNumber(0);
        }
        if(doc.getGoodNumber() == null){
            doc.setGoodNumber(0);
        }
        if(Global.TRUE.equals((doc.getIsTop()))){
            doc.setIsTop(Global.YES);
        }
        return super.saveOrUpdate(doc);
    }

    /**
     * 获取热门列表（浏览量排名前五，第二排序为是否置顶）
     * @return
     */
    @Override
    public List<Doc> findHotList() {
        return dao.findHotList();
    }

    @Override
    public List<Doc> listLink(Wrapper<Doc> wrapper) {
        return dao.listLink(wrapper);
    }
}
